<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>修改密码</title>
		<script src="../js/mui.js"></script>
		<link href="../css/mui.css" rel="stylesheet" />
		<script type="text/javascript" charset="utf-8">
			mui.init();
		</script>
		<link rel="stylesheet" href="../css/common.css" />
		<link rel="stylesheet" href="../css/reg.css" />
		<script type="text/javascript" src="../js/common.js"></script>
		<style>
			.note {
				width: 80%;
				display: none;
				color: white;
				height: 1rem;
				border-radius: 5%;
				background: #999999;
				text-align: center;
				line-height: 1rem;
				padding-left: 0.2rem;
				padding-right: 0.2rem;
				position: absolute;
				bottom: 1.5rem;
				left: 10%;
				opacity: 0.8;
			}
		</style>
	</head>

	<body>
		<div class="mui-content">
			<form class="mui-input-group">

				<div class="mui-input-row mui-radio reg_type">
					<span>密码类型</span> 登录密码
					<input type="radio" name="password" value="1" style="margin-top: 0.05rem;" /> 支付密码
					<input type="radio" name="password" value="2" />
				</div>
				<div class="mui-input-row">
					<label>原始密码</label>
					<input type="password" class="mui-input-clear password" placeholder="请输入您现在使用的密码">
				</div>
				<div class="mui-input-row">
					<label>新密码</label>
					<input type="password" class="mui-input-clear newPassword" placeholder="密码不小于6位">
				</div>
				<div class="mui-input-row">
					<label>确认密码</label>
					<input type="password" class="mui-input-clear re_password" placeholder="请确认密码">
				</div>

			</form>
			<div class="mui-content-padded">
				<button id='ok' class="mui-btn mui-btn-block mui-btn-danger">确认</button>
			</div>

			<div class="note"></div>
		</div>

	</body>

</html>
<script>
	document.getElementById("ok").addEventListener("tap", function() {
		function getRadioBoxValue(radioName) {
			var obj = document.getElementsByName("password");
			for (i = 0; i < obj.length; i++) {
				if (obj[i].checked) {
					return obj[i].value;
				}
			}
			return "undefined";
		}

		mui.ajax('/api/v1/user/password/change', {
			data: {
				paramStr: "{userName:" + sessionStorage.userName + ",token:" + sessionStorage.token + ",type:" + getRadioBoxValue() + ",password:" + document.querySelector(".password").value + ",newPassword:" + document.querySelector(".newPassword").value + "}"
			},
			dataType: 'json',
			type: 'post',
			success: function(data) {

				if (data.code == 200) {
					mui.alert(data.message, jump)

					function jump() {
						sessionStorage.clear();
						mui.openWindow({
							url: '../index.html',
						});
					}
					return
				}
				mui.alert(data.message)
			},
			error: function(xhr, type, errorThrown) {
				//异常处理；
				alert("未知错误")
			}
		});
	});
</script>